<!-- 充值 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>充值</title>
    <!-- bootstrap样式，地图插件使用 -->
    <link href="../../css/bootstrap.min.css" rel="stylesheet"/>
    <!-- layui -->
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <!-- 样式 -->
    <link href="../../css/style.css" rel="stylesheet"/>
    <!-- 主题（主要颜色设置） -->
    <link href="../../css/theme.css" rel="stylesheet"/>
    <!-- 通用的css -->
    <link href="../../css/common.css" rel="stylesheet"/>
</head>
<style>
    html::after {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
        content: '';
        display: block;
        background-attachment: fixed;
        background-size: cover;
        background-position: center;
        z-index: -1;
    }

    #swiper {
        overflow: hidden;
    }

    #swiper .layui-carousel-ind li {
        width: 50px;
        height: 1px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(1, 1, 1, 0.3);
        border-radius: 30px;
        background-color: rgba(255, 0, 0, 1);
        box-shadow: 0 0 0px rgba(255, 0, 0, .8);
    }

    #swiper .layui-carousel-ind li.layui-this {
        width: 50px;
        height: 10px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, 0.3);
        border-radius: 50px;
        background-color: rgba(0, 112, 126, 1);
        box-shadow: 0 0 0px rgba(15, 98, 108);
    }

    .index-title {
        text-align: center;
        box-sizing: border-box;
        width: 980px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
    }

    .index-title span {
        padding: 0 10px;
        line-height: 1.4;
    }

    .center-container .layui-nav-tree {
        width: 100%;
    }

    .center-container .layui-nav {
        position: inherit;
    }

    .center-container .layui-nav-tree .layui-nav-item {
        height: 44px;
        line-height: 44px;
        font-size: 14px;
        color: rgba(0, 112, 126, 1);
        border-width: 0;
        border-style: solid;
        border-color: rgba(38, 155, 158, 1);
        border-radius: 0;
        background-color: #fff;
        box-shadow: 0 0 6px rgba(0, 112, 126, 1);
        text-align: center;
    }

    .center-container .layui-nav-tree .layui-nav-bar {
        height: 44px !important;
        opacity: 0 !important;
    }

    .center-container .layui-nav-tree .layui-nav-item.layui-this {
        font-size: 14px;
        color: #fff;
        border-width: 1px;
        border-style: solid;
        border-color: rgba(38, 155, 158, 1);
        border-radius: 0px;
        background-color: rgba(38, 155, 158, 1);
        box-shadow: 0 0 0px rgba(0, 112, 126, 1);
    }

    .center-container .layui-nav-tree .layui-nav-item:hover {
        font-size: 14px;
        color: #fff;
        border-width: 0;
        border-style: solid;
        border-color: rgba(255, 0, 0, .3);
        border-radius: 0;
        background-color: rgba(38, 155, 158, 1);
        box-shadow: 0 0 6px rgba(255, 0, 0, 0);
    }

    .center-container .layui-nav-tree .layui-nav-item a {
        line-height: inherit;
        height: auto;
        background-color: inherit;
        color: inherit;
        text-decoration: none;
    }

    .right-container {
        position: relative;
    }

    .right-container .layui-form-item {
        display: flex;
        align-items: center;
    }

    .right-container .layui-input-block {
        margin: 0;
        flex: 1;
    }

    .right-container .input .layui-input {
        padding: 0 12px;
        height: 40px;
        font-size: 14px;
        color: #333;
        border-radius: 4px;
        border-width: 1px;
        border-style: solid;
        border-color: rgba(0, 112, 126, 1);
        background-color: #fff;
        box-shadow: 0 0 6px rgba(0, 112, 126, 1);
        text-align: left;
    }

    .right-container .select .layui-input {
        padding: 0 12px;
        height: 40px;
        font-size: 14px;
        color: #333;
        border-radius: 4px;
        border-width: 1px;
        border-style: solid;
        border-color: rgba(0, 112, 126, 1);
        background-color: #fff;
        box-shadow: 0 0 6px rgba(0, 112, 126, 1);
        text-align: left;
    }

    .right-container .date .layui-input {
        padding: 0 12px;
        height: 40px;
        font-size: 14px;
        color: #333;
        border-radius: 4px;
        border-width: 1px;
        border-style: solid;
        border-color: rgba(0, 112, 126, 1);
        background-color: #fff;
        box-shadow: 0 0 6px rgba(0, 112, 126, 1);
        text-align: left;
    }
</style>
<body>

<div id="app">

    <!-- 轮播图 -->
    <!-- <div class="layui-carousel" id="swiper">
        <div carousel-item id="swiper-item">
            <div v-for="(item,index) in swiperList" v-bind:key="index">
                <img class="swiper-item" :src="item.img">
            </div>
        </div>
    </div> -->
    <div :style='{"boxShadow":"0 0 6px rgba(15,98,108)","margin":"0 auto","borderColor":"rgba(0,0,0,.3)","borderRadius":"0px","borderWidth":"0","width":"100%","borderStyle":"solid"}' class="layui-carousel"
         id="swiper">
        <div carousel-item>
            <div :key="index" v-for="(item,index) in swiperList">
                <img :src="item.img" style="width: 100%;height: 100%;object-fit:cover;"/>
            </div>
        </div>
    </div>
    <!-- 轮播图 -->

    <!-- 标题 -->
    <!-- <h2 style="margin-top: 20px;" class="index-title">USER ADDRESS</h2>
    <div class="line-container">
        <p class="line" style="background: #EEEEEE;"> 收货地址添加 </p>
    </div> -->
    <div :style='{"padding":"10px","boxShadow":"10px 8px 6px rgba(0, 112, 126, 1)","margin":"10px auto","borderColor":"rgba(38, 155, 158, 1)","backgroundColor":"rgba(255, 255, 255, 1)","color":"rgba(0, 112, 126, 1)","borderRadius":"4px","borderWidth":"1px","fontSize":"20px","borderStyle":"solid","height":"auto"}'
         class="index-title">
        <span>USER ADDRESS</span><span>收货地址添加</span>
    </div>
    <!-- 标题 -->

    <div class="center-container">
        <!-- 个人中心菜单 config.js-->
        <div :style='{"padding":"0","boxShadow":"-1px 1px 6px rgba(0, 112, 126, 1)","margin":"0","borderColor":"rgba(38, 155, 158, 1)","backgroundColor":"#fff","borderRadius":"0","borderWidth":"0 0 1px 0","width":"160px","borderStyle":"solid"}'
             class="left-container">
            <ul class="layui-nav layui-nav-tree">
                <li :class="item.url=='../shop-address/list.html'?'layui-this':''" class="layui-nav-item" v-bind:key="index"
                    v-for="(item,index) in centerMenu">
                    <a :href="'javascript:window.location.href=\''+item.url+'\''">{{item.name}}</a>
                </li>
            </ul>
        </div>
        <!-- 添加地址表单 -->
        <div :style='{"padding":"20px","boxShadow":"0px 0px 0px rgba(0, 112, 126, 1)","margin":"0","borderColor":"rgba(0, 112, 126, 1)","backgroundColor":"#fff","borderRadius":"0","borderWidth":"0","borderStyle":"solid"}'
             class="right-container">
            <form class="layui-form" lay-filter="myForm" style="margin-top: 20px;">
                <div :style='{"padding":"10px","boxShadow":"0 0 6px rgba(0, 112, 126, 1)","margin":"0 0 10px 0","borderColor":"rgba(0, 112, 126, 1)","backgroundColor":"#fff","borderRadius":"4px","borderWidth":"0 0 1px 0","borderStyle":"solid"}'
                     class="layui-form-item layui-form-text">
                    <label :style='{"width":"94px","padding":"0 12px 0 0","fontSize":"14px","color":"rgba(0, 112, 126, 1)","textAlign":"right"}'
                           class="layui-form-label">联系人：</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="name" lay-verify="required" name="name" placeholder="联系人"
                               required
                               type="text">
                    </div>
                </div>
                <div :style='{"padding":"10px","boxShadow":"0 0 6px rgba(0, 112, 126, 1)","margin":"0 0 10px 0","borderColor":"rgba(0, 112, 126, 1)","backgroundColor":"#fff","borderRadius":"4px","borderWidth":"0 0 1px 0","borderStyle":"solid"}'
                     class="layui-form-item layui-form-text">
                    <label :style='{"width":"94px","padding":"0 12px 0 0","fontSize":"14px","color":"rgba(0, 112, 126, 1)","textAlign":"right"}'
                           class="layui-form-label">手机号码：</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="phone" lay-verify="required|phone" name="phone"
                               placeholder="手机号码" required
                               type="text">
                    </div>
                </div>
                <div :style='{"padding":"10px","boxShadow":"0 0 6px rgba(0, 112, 126, 1)","margin":"0 0 10px 0","borderColor":"rgba(0, 112, 126, 1)","backgroundColor":"#fff","borderRadius":"4px","borderWidth":"0 0 1px 0","borderStyle":"solid"}'
                     class="layui-form-item layui-form-text">
                    <label :style='{"width":"94px","padding":"0 12px 0 0","fontSize":"14px","color":"rgba(0, 112, 126, 1)","textAlign":"right"}'
                           class="layui-form-label">默认地址：</label>
                    <div class="layui-input-block" style="width: 300px;text-align: left;">
                        <input checked name="isdefault" title="是" type="radio" value="是">
                        <input name="isdefault" title="否" type="radio" value="否">
                    </div>
                </div>
                <div :style='{"padding":"10px","boxShadow":"0 0 6px rgba(0, 112, 126, 1)","margin":"0 0 10px 0","borderColor":"rgba(0, 112, 126, 1)","backgroundColor":"#fff","borderRadius":"4px","borderWidth":"0 0 1px 0","borderStyle":"solid"}'
                     class="layui-form-item layui-form-text">
                    <label :style='{"width":"94px","padding":"0 12px 0 0","fontSize":"14px","color":"rgba(0, 112, 126, 1)","textAlign":"right"}'
                           class="layui-form-label">选择地址：</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="address" lay-verify="required" name="address"
                               placeholder="选择地址" required
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="display: flex;flex-wrap:wrap;">
                        <button :style='{"padding":"0 10px","boxShadow":"0 0  0px rgba(0, 112, 126, 1)","margin":"10px auto 0","borderColor":"rgba(38, 155, 158, 1)","backgroundColor":"rgba(38, 155, 158, 1)","color":"#fff","borderRadius":"8px","borderWidth":"0","width":"60%","fontSize":"14px","borderStyle":"solid","height":"44px"}'
                                class="layui-btn btn-submit"
                                lay-filter="*" lay-submit style="outline:none">修改
                        </button>
                        <button :style='{"padding":"0 10px","boxShadow":"0 0 6px rgba(0, 112, 126, 1)","margin":"10px auto","borderColor":"#ccc","backgroundColor":"#fff","color":"rgba(0, 0, 0, 1)","borderRadius":"8px","borderWidth":"0","width":"60%","fontSize":"14px","borderStyle":"solid","height":"44px"}'
                                class="layui-btn layui-btn-primary"
                                style="outline:none" type="reset">重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>

<!-- layui -->
<script src="../../layui/layui.js"></script>
<!-- vue -->
<script src="../../js/vue.js"></script>
<!-- 组件配置信息 -->
<script src="../../js/config.js"></script>
<!-- 扩展插件配置信息 -->
<script src="../../modules/config.js"></script>
<!-- 工具方法 -->
<script src="../../js/utils.js"></script>
<!-- 校验格式工具类 -->
<script src="../../js/validate.js"></script>
<!-- 地图 -->
<script src="../../js/jquery.js" type="text/javascript"></script>
<script src="http://webapi.amap.com/maps?v=1.3&key=ca04cee7ac952691aa67a131e6f0cee0" type="text/javascript"></script>
<script src="../../js/bootstrap.min.js" type="text/javascript"></script>
<script src="../../js/bootstrap.AMapPositionPicker.js" type="text/javascript"></script>

<script>
    var jquery = $;

    var vue = new Vue({
        el: '#app',
        data: {
            // 轮播图
            swiperList: [{
                img: '../../img/banner.jpg'
            }],
            centerMenu: centerMenu
        },
        filters: {
            newsDesc: function (val) {
                if (val) {
                    if (val.length > 200) {
                        return val.substring(0, 200).replace(/<[^>]*>/g).replace(/undefined/g, '');
                    } else {
                        return val.replace(/<[^>]*>/g).replace(/undefined/g, '');
                    }
                }
                return '';
            }
        },
        methods: {
            jump(url) {
                jump(url)
            }
        }
    })

    // 初始化地图插件
    jquery(document).ready(function () {
        var p = jquery("#address").AMapPositionPicker();
        jquery("#address").on('click', function () {
            var position = p.AMapPositionPicker('position');
            jquery('#address').val(position.address)
        });
    });

    layui.use(['layer', 'element', 'carousel', 'http', 'jquery', 'form', 'laypage'], function () {
        var layer = layui.layer;
        var element = layui.element;
        var carousel = layui.carousel;
        var http = layui.http;
        var jquery = layui.jquery;
        var laypage = layui.laypage;
        var form = layui.form;

        var id = http.getParam('id');

        // 获取轮播图 数据
        http.request('config/list', 'get', {
            page: 1,
            limit: 5
        }, function (res) {
            if (res.data.list.length > 0) {
                var swiperItemHtml = '';
                for (let item of res.data.list) {
                    if (item.name.indexOf('picture') >= 0 && item.value && item.value != "" && item.value != null) {
                        swiperItemHtml +=
                            '<div>' +
                            '<img style="width: 100%;height: 100%;object-fit:cover;" class="swiper-item" src="' + item.value + '">' +
                            '</div>';
                    }
                }
                jquery('#swiper-item').html(swiperItemHtml);
                // 轮播图
                vue.$nextTick(() => {
                    carousel.render({
                        elem: '#swiper',
                        width: '100%',
                        height: '400px',
                        arrow: 'hover',
                        anim: 'fade',
                        autoplay: 'true',
                        interval: '3000',
                        indicator: 'inside'
                    });

                })
            }
        });


        // 表单校验
        form.verify({
            phone: function (value, item) {
                if (!isMobile(value)) {
                    return '请输入正确的手机号码'
                }
            },
        });

        // 提交表单
        form.on('submit(*)', function (data) {
            data = data.field;
            data.id = id;
            data.userid = localStorage.getItem('userid');
            console.log(data);
            http.requestJson(`address/update`, 'post', data, function (data) {
                layer.msg('修改成功', {
                    time: 2000,
                    icon: 6
                }, function () {
                    window.history.go(-1);
                });
            });
            return false
        });

        // 获取数据
        http.request(`address/info/${id}`, 'get', {}, function (data) {
            // 表单赋值
            form.val("myForm", data.data);
        });

    });
</script>
</body>
</html>
